/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wanhai.itm.wditm101.vm;

import com.wanhai.bizbean.SFPParameter;
import com.wanhai.itm.util.DataSetService;
import com.wanhai.itm.util.LoadOption;
import com.wanhai.itm.util.WD_DefaultVM;
import com.wanhai.itm.wditm101.vo.Wditm101_ITM4002VO;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Include;
import org.zkoss.zul.Window;

/**
 *
 * @author m2434
 */
public class Wditm101_holidayVM extends WD_DefaultVM<Wditm101_ITM4002VO> {
    
    private List<SelectItem> yearQueryList = new ArrayList<SelectItem>();
    private List<SelectItem> pmOffList= LoadOption.getYesOrNo();
    
    private DataSetService dsService = new DataSetService();
    
    ///<editor-fold defaultstate="collapsed" desc="binding UI component">
    @Wire("#inc_batchInsert")
    protected Include incBatchInsert;
    //</editor-fold>
    
    public Wditm101_holidayVM(){
        super(Wditm101_ITM4002VO.class);
    }
    
    @Init
    public void init(){
        for(int i=2015 ; i<2018 ; i++){
            this.getYearQueryList().add(new SelectItem(i,String.valueOf(i)));
        }
        
    }
    
    @Command("preInsert")
    @NotifyChange({"selected","actionFlag"})
    public void preInsert() throws Exception{
        super.setActionFlag("insert");
        
        //default value
        Wditm101_ITM4002VO insertVo = new Wditm101_ITM4002VO();
        insertVo.setPM_OFF("N");
        insertVo.setWORKING_HOURS("0");
        
        super.setSelected(insertVo);
        
        ((Window)inc1.getFellow("operatorWin")).doModal();
    }
    
    @Command("preBatchInsert")
    public void preBatchInsert() throws Exception{
        this.setSelected(new Wditm101_ITM4002VO());
        
        ((Window)incBatchInsert.getFellow("operatorWin")).doModal();
    }
    
    @Command("batchInsert")
    public void batchInsert() throws Exception{
        
        ArrayList<SFPParameter> params = new ArrayList<SFPParameter>();
        params.add(new SFPParameter(getSelected().getNATION_OR_OFFICE(), SFPParameter.Types.STRING, SFPParameter.IN));
        params.add(new SFPParameter(getSelected().getYear(), SFPParameter.Types.STRING, SFPParameter.IN));
        params.add(new SFPParameter(super.user.getUserCode(), SFPParameter.Types.STRING, SFPParameter.IN));
        params.add(new SFPParameter(super.user.getOfficeCode(), SFPParameter.Types.STRING, SFPParameter.IN));
        
        dsService.callSFP("P", "SP_ITM_0001", params);
        
        this.setCond(this.getSelected());
        this.query();
        this.clearCond();
        incBatchInsert.getFellow("operatorWin").setVisible(false);
        
        Clients.showNotification("batch insert complete","info",null,"top_right",2000);
    }
    
    @AfterCompose
    public void afterCompose(@ContextParam(ContextType.VIEW) Component view){
        Selectors.wireComponents(view, this, false);
    }

    //<editor-fold defaultstate="collapsed" desc="getter, setter">
    public List<SelectItem> getYearQueryList() {
        return yearQueryList;
    }
    
    public void setYearQueryList(List<SelectItem> yearQueryList) {
        this.yearQueryList = yearQueryList;
    }
    
    public List<SelectItem> getPmOffList() {
        return pmOffList;
    }

    public void setPmOffList(List<SelectItem> pmOffList) {
        this.pmOffList = pmOffList;
    }
    //</editor-fold>

    
    
}
